﻿<!DOCTYPE>

<html>

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
  <title>工序检测项修改</title>
  <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
  <style type="text/css">
    .linkbutton {
      margin-left: 20px;
      width: 85px;
    }

    table tr td {
      padding: 0px 5px
    }
  </style>
</head>

<body>
  <div class="panelSection">
    <div class="easyui-panel " title="查询区域" style="padding:3px;width:100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <form id="searchForm" method="post">
        <table>
          <tr class="divLabel">
            <td>订单号:</td>
            <td>批号:</td>
            <td>件号:</td>
            <td>分厂:</td>
            <td>开卡人:</td>
            <td>工区:</td>
            <td>是否领料:</td>
            <td>开卡开始/结束日期:</td>
          </tr>
          <tr>
            <td><input class="easyui-textbox" type="text" name="txtMfgOrder" style="width: 120px; height: 22px" /></td>
            <td><input class="easyui-textbox" type="text" name="txtContainer" style="width: 120px; height: 22px" /></td>
            <td><input class="easyui-textbox" type="text" name="txtProduct" style="width: 120px; height: 22px" /></td>
            <td><input type="text" name="txtFactory" style="width: 120px; height: 22px" id="ddlFactory" /></td>
            <td><input class="easyui-textbox" type="text" name="txtEmployeeName" style="width: 120px; height: 22px"
                data-options="value:'%'" /></td>
            <td><input type="text" name="txtWorkcenter" style="width: 120px; height: 22px" id="ddlWorkcenter" /></td>
            <td><input id="txtPrintType" name="txtPrintType" style="width: 120px; height: 22px" /></td>
            <td>
              <input class="easyui-datebox" name="txtStartDate" style="width: 120px; height: 22px" />至
              <input class="easyui-datebox" name="txtEndDate" style="width: 120px; height: 22px" />
            </td>
            <td><a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchData()">查询</a>
            </td>
            <td><a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchReset()">重置</a>
            </td>
            <td></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
  <div class="panelSection">
    <div class="easyui-panel " title="流水卡区域" style="padding:3px;width:100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <table id="txtContainer" style="height:300px;width:100%"></table>
      <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
      </div>
    </div>
  </div>
  <div class="panelSection" id="EditorpanelSection">
    <div class="easyui-panel " title="编辑区域" style="padding:3px;width:100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div style="width:68%;float: left">
        <table id="txtStepCheckPoint" style="height:300px;width:100%"></table>
      </div>
      <div style="width:30%;float:left;margin-left:5px" id="editIframe">
        <iframe src="/InSiteWebApplication/forms/Custom/htmlPage/StepCheckPoint/CheckPointSymbolInput.aspx"
          width="390px" height="340px" scrolling="no" id="pointContent" style="border:none"></iframe>
      </div>
    </div>
  </div>
  <div class="panelSection">
    <div class="easyui-panel " title="按钮区域" style="padding:3px;width:100%"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div style="margin:15px 0px">
        <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.SaveCheckPointResultUpdate()"
          id="Confirm">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.AuditCheckPointResultUpdate()"
          id="Audit">审核</a>
      </div>
    </div>
  </div>
  <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
  <div id="dlg" style="display:none">
    <div style="margin:10px">
      <form id="ff">
        <input class="easyui-radiobutton" name="isok" value="0" label="同意" labelPosition="after" checked="true">
        <input class="easyui-radiobutton" name="isok" value="1" label="不同意" labelPosition="after">
        <div style="width:100%;padding-top:20px">备注:<input class="easyui-textbox" labelPosition="left"
            style="width:80%;" name="note"></div>
      </form>
    </div>
  </div>
</body>

</html>

<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
  /*
  创建人：longb
  日期：2024-10-21
  描述：检测结果修改js
  */
  var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    pageType: getParam("type"), //1：修改 2：审核
    ajaxUrl: getRootPath() + "/Ashx/StepCheckPointResultEditHandler.ashx",
    //初始化页面
    init: function () {
      page.initPageData();
      page.bind();
      customizedEasyuiPagination('pp'); //定制化分页
      if (page.pageType == "1") { $('#Confirm,#editIframe').show(); $('#Audit').hide(); }
      if (page.pageType == "2") { $('#Confirm,#editIframe').hide(); $('#Audit').show(); }
    },
    initPageData: function () {
      var param = {
        action: "initPageData",
      };
      page.post(param, function (res) {
        if (res.Result) {
          $('#ddlFactory').combobox({
            data: res.ReturnData,
            valueField: 'FACTORYNAME',
            textField: 'FACTORYNAME',
            value: '',
            panelHeight: 'auto'
          });
          $('#ddlWorkcenter').combobox({
            data: res.DBTable,
            valueField: 'WORKCENTERNAME',
            textField: 'WORKCENTERNAME',
            value: '',
            panelHeight: 'auto'
          });
        }
      });
    },
    //页面事件绑定
    bind: function () {
      var Initid = 0;
      var data = [{ id: '', text: '全部' }, { id: '1', text: '自制' }, { id: '0', text: '领料' }];
      $('#txtPrintType').combobox({
        data: data,
        valueField: 'id',
        textField: 'text',
        value: '',
        panelHeight: 'auto'
      });
      //批次信息
      $("#txtContainer").datagrid({
        checkOnSelect: false,
        selectOnCheck: false,
        singleSelect: true,
        rownumbers: true,
        onLoadSuccess: function (data) {
          $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
            total: page.pagetotal,
            pageSize: page.pageSize,
            pageNumber: page.pageNumber
          });
          customizedEasyuiPagination('pp'); //定制化分页
        },
        columns: [[
          { field: 'MFGORDERNAME', title: '生产订单号', width: 130 },
          { field: 'CONTAINERBATCH', title: '批次号', width: 150 },
          { field: 'FACTORYSTARTDATE', title: '创建时间', width: 150 },
          { field: 'DESCRIPTION', title: '零件名称', width: 120 }, //--
          { field: 'QTY', title: '数量', width: 90, align: 'center' },
          { field: 'FULLNAME', title: '开卡人', width: 90, align: 'center' },
          { field: 'WORKCENTERNAME', title: '工区', width: 100 },
          { field: 'FACTORYNAME', title: '分厂', width: 100 },
          { field: 'MAINORSONCONTAINER', title: '主子卡', width: 90, align: 'center' },
          { field: 'FACONTAINERNAME', title: '主制批次', width: 90, align: 'center' }
        ]],
        onSelect: function (index, row) {
          page.GetStepCheckListData(row);
        }
      });
      //分页事件
      $('#pp').pagination({
        onSelectPage: function (pageNumber, pageSize) {
          customizedEasyuiPagination('pp'); //定制化分页
          page.pageSize = pageSize; page.pageNumber = pageNumber;
          page.GetContainerData();
        }
      });
      //绑定分页go按钮
      $('#pageGo').on("click", function () {
        var pageNumber = $(this).parents('tr').find('.pagination-num').val();
        page.pageNumber = pageNumber;
        page.GetContainerData();
      });
      //清除按钮
      $('#btnReset').on("click", function () {
        page.reset(true, true);
        page.pageNumber = 1; page.pagetotal = 0
        $('#pp').pagination('refresh', {
          total: page.pagetotal,
          pageSize: page.pageSize,
          pageNumber: page.pageNumber
        });
      });
      //工序检测项信息
      $("#txtStepCheckPoint").datagrid({
        checkOnSelect: true,
        selectOnCheck: false,
        singleSelect: true,
        rownumbers: true,
        columns: [[
          { field: 'STEPCHECKPOINTRESULTID', checkbox: true },
          { field: 'WORKFLOWSTEPNAME', title: '工序名称', width: 130 },
          { field: 'NAME', title: '关重符号', width: 80 },
          { field: 'CHECKPOINTNOTEDIS', title: '检测项内容描述', width: 150 },
          { field: 'DRAWINGREQUIREDIS', title: '图纸规定', width: 120 }, //--
          { field: 'BUBBLENUMBER', title: '气泡号', width: 120 }, //--
          { field: 'WORKCHECKPOINTRESULTNOTEDIS', title: '工人实测值', width: 120, align: 'center' },
          { field: 'CHECKPOINTRESULTNOTEDIS', title: '检验实测值', width: 120, align: 'center' },
          //{ field: 'OLDWORKCHECKPOINTRESULTNOTE', title: '工人实测（原）值', width: 120,styler: function(value,row,index){return 'background-color:#F0F2F5'} }, 
          { field: 'OLDCHECKPOINTRESULTNOTE', title: '检验实测（原）值', width: 120, styler: function (value, row, index) { return 'background-color:#F0F2F5' } },
          //{ field: 'NEWWORKCHECKPOINTRESULTNOTE', title: '工人实测（新）值', width: 120,styler: function(value,row,index){return 'background-color:#F0F2F5'} },
          { field: 'NEWCHECKPOINTRESULTNOTE', title: '检验实测（新）值', width: 120, styler: function (value, row, index) { return 'background-color:#F0F2F5' } },
          { field: 'UPDATENAME', title: '修改人', width: 90, align: 'center' },
          { field: 'UPDATETIME', title: '修改时间', width: 150, align: 'center' },
          { field: 'AUDITNAME', title: '审批人', width: 90, align: 'center' },
          { field: 'AUDITTIME', title: '审批时间', width: 150, align: 'center' },
          { field: 'AUDITRESULT', title: '审批结果', width: 100, align: 'center' },
          { field: 'NOTE', title: '备注', width: 150, align: 'center' }
        ]],
        onSelect: function (index, row) {
          page.reset(false, false);
          if (page.pageType == "2") { return; }
          $("#txtStepCheckPoint").datagrid("uncheckAll");//.datagrid("unselectAll");
          if (isNullOrWhiteSpaceStr(row.STEPCHECKPOINTRESULTID)) {
            displayMessage('请勾选一条已录入检测值的记录再进行操作', false);
            return;
          }
          var rows = $("#txtStepCheckPoint").datagrid("getRows");
          //var maxRows=rows.filter(item=>item.CN>0);
          //var fileterRow=maxRows.filter(item=>item.STEPCHECKPOINTRESULTID==row.STEPCHECKPOINTRESULTID);//选中行是否已存在录入
          var maxRows = [];
          for (var i = 0; i < rows.length; i++) {
            if (rows[i].CN > 0) {
              maxRows.push(rows[i]);
            };
          }
          var fileterRow = [];
          for (var i = 0; i < maxRows.length; i++) {
            if (maxRows[i].STEPCHECKPOINTRESULTID == row.STEPCHECKPOINTRESULTID) {
              fileterRow.push(maxRows[i]);
            };
          }

          //if (maxRows.length >= 2 && fileterRow.length == 0) {
          //  displayMessage("该批次检测项记录已存在两条修改记录，禁止再调整", false);
          //  return;
          //}
          //if (row.ACN >= 2) {
          //  displayMessage("该检测项记录已录入两次数据，禁止再调整", false);
          //  return;
          //} else {
            $("#txtStepCheckPoint").datagrid("checkRow", index);//单选行，去掉同时勾选
          //}
        }
      });
    },
    //查询
    searchData: function () {
      page.reset(false, true);
      page.pageNumber = 1;
      page.GetContainerData();
      $('#txtStepCheckPoint').datagrid('loadData', []);
    },

    //查询批次信息
    GetContainerData: function () {
      var frdata = $('#searchForm').serializeArray();
      var data = {};
      $.each(frdata, function () {
        data[this.name] = this.value
      });
      var param = {
        action: "GetContainerData",
        pageSize: page.pageSize,
        pageNumber: page.pageNumber,
        data: JSON.stringify(data),
        type: page.pageType
      };
      page.post(param, function (res) {
        if (res.Result) {
          //console.info(res);
          page.pagetotal = res.RowCount;
          $('#txtContainer').datagrid('loadData', res.DBTable);
        } else {
          displayMessage(res.Message, res.Result);
        }
      });
    },
    //查询检测项结果
    GetStepCheckListData: function (row) {
      page.reset(false, false);
      $('#txtStepCheckPoint').datagrid('loadData', []);
      var param = {
        action: "GetStepCheckListData",
        data: JSON.stringify(row)
      };
      page.post(param, function (res) {
        if (res.Result) {
          $('#txtStepCheckPoint').datagrid('loadData', res.DBTable);
        } else {
          displayMessage(res.Message, res.Result);
        }
      });
    },
    //--保存--
    SaveCheckPointResultUpdate: function () {
      var rows = $('#txtStepCheckPoint').datagrid('getChecked');
      var row = $('#txtContainer').datagrid('getSelected');
      if (rows.length == 0 || rows.length > 1) {
        displayMessage('请勾选一条检测项记录再进行操作', false);
        return;
      }
      if (isNullOrWhiteSpaceStr(rows[0]["STEPCHECKPOINTRESULTID"])) {
        displayMessage('请勾选一条已录入检测值的记录再进行操作', false);
        return;
      }
      //if (rows[0].CN >= 2) {
      //  displayMessage("该检测项记录已录入两次数据，禁止再调整", false);
      //  return;
      //}
      var strCode = $("#pointContent").contents().find("#wucToleranceInput1_ftbFinalHtml_designEditor").contents().find("body").html();
      if (isNullOrWhiteSpaceStr(strCode)) {
        displayMessage('请填写检测值数据', false);
        return;
      }
      var srow = rows[0];
      srow.strCode = strCode
      var param = {
        action: "SaveStepCheckPointRecordData",
        data: JSON.stringify(srow),
        container: JSON.stringify(row)
      };
      page.post(param, function (res) {
        if (res.Result) {
          page.GetStepCheckListData(row);
          $("#pointContent").contents().find("#wucToleranceInput1_ftbFinalHtml_designEditor").contents().find("body").html('')
        }
        displayMessage(res.Message, res.Result);
      });

    },

    //--审核
    AuditCheckPointResultUpdate: function () {
      var rows = $('#txtStepCheckPoint').datagrid('getChecked');
      var allRows = $("#txtStepCheckPoint").datagrid("getRows");
      //var maxRows=rows.filter(item=>item.NEWCHECKPOINTRESULTNOTE!=null&&item.AUDITNAME==null);
      var maxRows = [];
      for (var i = 0; i < rows.length; i++) {
        if (rows[i].NEWCHECKPOINTRESULTNOTE != null && rows[i].AUDITNAME == null) {
          maxRows.push(rows[i]);
        };
      }
      if (maxRows.length == 0) {
        displayMessage('请勾选已调整且未审批检测项记录再进行操作', false);
        return;
      }
      var auditRows = [];
      for (var i = 0; i < allRows.length; i++) {
        if (allRows[i].AUDITNAME != null) {
          auditRows.push(allRows[i]);
        };
      }
      //if (maxRows.length + auditRows.length > 2) {
      //  displayMessage('勾选的记录+已审核记录数>最大审批数2条，请重新选择', false);
      // return;
      //}

      $('#dlg').dialog({
        title: '审批',
        width: 400,
        height: 200,
        closed: false,
        cache: false,
        modal: true,
        buttons: [{
          text: '确认',
          handler: function () {
            var frdata = $('#ff').serializeArray();
            var data = {};
            $.each(frdata, function () {
              data[this.name] = this.value
            });
            if (data.isok == "1" && isNullOrWhiteSpaceStr(data.note)) {
              displayMessage2("请输入不同意原因", false);
              return;
            }
            var param = {
              action: "AuditCheckPointResultUpdate",
              data: JSON.stringify(maxRows),
              para: JSON.stringify(data)
            };
            page.post(param, function (res) {
              if (res.Result) {
                var row = $('#txtContainer').datagrid('getSelected');
                page.GetStepCheckListData(row);
                $("#pointContent").contents().find("#wucToleranceInput1_ftbFinalHtml_designEditor").contents().find("body").html('')
                $('#dlg').dialog('close')
              }
              displayMessage(res.Message, res.Result);
            });
          }
        }, {
          text: '取消',
          handler: function () {
            $('#dlg').dialog('close')
          }
        }]
      });
    },

    //查询重置
    searchReset: function () {
      $('#searchForm').form('clear');
      page.bind();
    },

    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
      clearMessage();
    },
    //post数据
    post: function (param, callback) {
      $.ajax({
        type: "Post",
        url: page.ajaxUrl,
        data: param,
        cashe: false,
        async: true,
        dataType: "json",
        beforeSend: function () {
          $.messager.progress({ text: '', msg: '处理中...' });
        },
        success: function (data) {
          $.messager.progress('close');
          callback(data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $.messager.progress('close');
          displayMessage(XMLHttpRequest.responseText, false);
        }
      });
    }
  }
  $(function () {
    page.init();
  });
</script>